package com.d3works.apps.hr.db.repo;

import com.d3works.apps.account.db.repo.PartnerAccountRepository;
import com.d3works.apps.account.service.AccountingSituationInitService;
import com.d3works.apps.base.db.Partner;
import com.d3works.apps.base.service.app.AppService;
import com.d3works.apps.hr.exception.HumanResourceExceptionMessage;
import com.d3works.i18n.I18n;
import com.google.inject.Inject;
import javax.persistence.PersistenceException;

public class PartnerHRRepository extends PartnerAccountRepository {

  @Inject
  public PartnerHRRepository(
      AppService appService, AccountingSituationInitService accountingSituationInitService) {
    super(appService, accountingSituationInitService);
  }

  @Override
  public void remove(Partner partner) {
    if (partner.getEmployee() != null) {
      throw new PersistenceException(
          String.format(
              I18n.get(HumanResourceExceptionMessage.CONTACT_CANNOT_DELETE),
              partner.getPartnerSeq(),
              partner.getSimpleFullName()));
    }
    super.remove(partner);
  }
}
